<template>
<div class="product-add">
    <!--form表单-->
    <el-form size="small" ref="form" :model="form" label-width="150px">
      <!--添加门店-->
      <div class="common-form">{{$t('setting.order_flow_settings')}}</div>
      <el-form-item :label="$t('setting.unpaid_orders')">
        <el-input
          v-model="form.closeDays"
          type="number"
          style="width: 200px"
        ></el-input>
        <el-select
          size="small"
          v-model="form.closeType"
          :placeholder="$t('setting.days')"
          type="number"
          style="width: 80px"
        >
          <el-option
            v-for="(item, index) in closeTypeList"
            :key="index"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select> {{$t('setting.auto_close_suffix')}} 

<div class="tips">{{$t('setting.unpaid_order_rule')}}</div>
      </el-form-item>
      <el-form-item :label="$t('setting.shipped_orders')">
        <el-input
          v-model="form.receiveDays"
          type="number"
          style="width: 200px"
        ></el-input> {{$t('setting.auto_confirm_suffix')}} 

<div class="tips"> {{$t('setting.confirm_rule_tip')}} 

</div>
      </el-form-item>
      <el-form-item :label="$t('setting.completed_orders')">
        <el-input
          v-model="form.refundDays"
          type="number"
          style="width: 200px"
        ></el-input> {{$t('setting.after_sales_window')}} 

<div class="tips"> {{$t('setting.after_sales_rule_tip')}} 

</div>
      </el-form-item>

      <div class="common-form">{{$t('setting.freight_settings')}}</div>
      <el-form-item :label="$t('setting.freight_strategy')">
        <el-col>
          <el-radio v-model="form.freightRule" :label="10">{{$t('setting.freight_addition')}}</el-radio>
          <div class="tips"> {{$t('setting.freight_addition_note')}} 

</div>
        </el-col>
        <div style="margin-top: 20px">
          <el-radio v-model="form.freightRule" :label="20"
            >{{$t('setting.freight_min')}}</el-radio
          >
          <el-col class="tips"> {{$t('setting.freight_min_note')}} 

</el-col>
        </div>
        <el-col style="margin-top: 20px">
          <el-radio v-model="form.freightRule" :label="30"
            >{{$t('setting.freight_max')}}</el-radio
          >
          <div class="tips"> {{$t('setting.freight_max_note')}} 

</div>
        </el-col>
      </el-form-item>

      <!--提交-->
      <div class="common-button-wrapper">
        <el-button type="primary" @click="onSubmit" :loading="loading"
          >{{$t('setting.submit_button')}}</el-button
        >
      </div>
    </el-form>
  </div>
</template>

<script>
import SettingApi from "@/api/setting.js";
export default {
  data() {
    return {
      /*切换菜单*/
      // activeIndex: '1',
      /*form表单数据*/
      form: {
        closeDays: "",
        closeType: 1,
        receiveDays: "",
        refundDays: "",
        freightRule: ""
      },
      closeTypeList: [{
        id: 1,
        name: $t("setting.days")
      }, {
        id: 2,
        name: $t("setting.hours")
      }, {
        id: 3,
        name: $t("setting.minutes")
      }],
      loading: false
    };
  },
  created() {
    this.getParams();
  },
  methods: {
    getParams() {
      let self = this;
      SettingApi.tradeDetail({}, true).then(res => {
        if (res.code == 1) {
          let vars = res.data;
          self.form.closeDays = vars.closeDays;
          self.form.receiveDays = vars.receiveDays;
          self.form.refundDays = vars.refundDays;
          self.form.freightRule = vars.freightRule;
          self.form.closeType = vars.closeType;
        }
      }).catch(error => {});
    },
    //监听复选框选中
    handleCheckedCitiesChange(val) {},
    onSubmit() {
      let self = this;
      self.loading = true;
      let form = self.form;
      SettingApi.editTrade(form, true).then(data => {
        self.loading = false;
        ElMessage({
          message: $t("setting.transaction_setting_success"),
          type: "success"
        });
        self.$router.push("/setting/trade/index");
      }).catch(error => {
        self.loading = false;
      });
    }
  }
};
</script>

<style>
.tips {
  color: #ccc;
}
</style>

